<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSON</title>
    <script>
        function f1(){
            let user = {"id":1,"username":"admin","password":"123456"};
            console.log(user.id); // get方法
            user.id = 2;    // set方法
            console.log(user.id);
            console.log(user["username"]);
            console.log(user['password']);
        }
        function f2(){
            let address = {"province":"江苏","city":"南京"};
            let user = {"id":1,"name":"李白","address":address};
            let user2 = {"1id":1,"name":"李白","address":{"province":"江苏","city":"苏州"}};
            console.log(user.address.province);
            console.log(user['address'].city);
            console.log(user2['address']['city']);
            // 变量名不建议使用数字开头
            console.log(user2['1id']);
        }
        function f3(){
            let users = [
                {"id":1,"username":"admin","password":"123456"},
                {"id":2,"username":"alice","password":"654321"},
                {"id":3,"username":"tom","password":"666666"}
            ];
            console.log(users[0].id);
            console.log(users[1]['username']);
            console.log(users[2]['password']);
        }
    </script>
</head>
<body>
<button onclick="f1()">基本语法</button><br>
<button onclick="f2()">对象中包含对象</button><br>
<button onclick="f3()">对象数组</button><br>
</body>
</html>